package com.haiyou.dc.message.util;

import lombok.extern.slf4j.Slf4j;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;


/**
 * @author pc
 */
@Slf4j
public class PropertiesUtil {
    private static Properties props = null;

    /**
     * 加载配置文件
     */
    private static void readProperties() {
        String fileName = "application.properties";
        try {
            props = new Properties();
            InputStream inputStream = PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName);
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
            props.load(inputStreamReader);
        } catch (Exception e) {
            log.error("加载配置文件失败==fileName" + fileName + "," + e.getMessage(), e);
        }
    }

    /**
     * 根据key读取对应的value
     *
     * @param key
     * @return
     */
    public static String get(String key) {
        if (props == null) {
            readProperties();
        }
        return props.getProperty(key);
    }


}
